<template>
  <div class="Bindmobile">
    <Head msg="关联账号"></Head>
    <div class="login-list">
      <div>手机号：</div>
      <input type="number" placeholder="请输入手机号" v-model="tel" />
    </div>
    <div class="login-list">
      <div>密码：</div>
      <input type="password" placeholder="请输入密码" v-model="psd" />
    </div>
    <div class="login-list">
      <div>验证码：</div>
      <input
        type="text"
        placeholder="请输入验证码"
        class="login-code-input"
        v-model="code"
      />
    </div>
    <div class="login-code-main">
      <img class="login-code" :src="codeurl" />
      <div class="code-fresh-btn" @click="codeFresh">刷新</div>
    </div>
    <div class="login-btn" @click="bindMobile">关联账户</div>
  </div>
</template>

<script lang="ts">
import { Component } from 'vue-property-decorator';
import Sence from '../sence/Sence';
// import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
import Head from '@/components/Head.vue';

@Component({
  components: {
    Head,
  },
})
export default class Bindmobile extends Sence {
  public tel: string = '';
  public psd: string = '';
  public code: string = '';
  public codeurl: string = this.apiurl + 'captcha.html';

  public codeFresh(): void {
    const that = this;
    that.codeurl = this.apiurl + 'captcha.html?d=' + Math.random();
  }

  public bindMobile(): void {
    if (this.tel.length != 11) {
      this.toast('手机号输入错误！', 'warn');
      return;
    } else if (this.psd == '') {
      this.toast('密码不能为空！', 'warn');
      return;
    } else if (this.code == '') {
      this.toast('验证码不能为空！', 'warn');
      return;
    }

    const that = this;
    that
      .post('api/v1/bindMobile', {
        mobile: that.tel,
        passwd: that.psd,
        captcha: that.code,
      })
      .then((res: any) => {
        that.toast('关联成功');
        setTimeout(() => {
          (<any>that).$router.push('/mine');
        }, 2000);
      });
  }
}
</script>

<style scoped lang="stylus">
input {
  border: 1px solid #808080;
  height: 25px;
}

.login-title {
  height: 80px;
  text-align: center;
  background: #4876ff;
  color: white;
  font-weight: bold;
  font-size: 16px;
  line-height: 80px;
  margin-bottom: 50px;
}

.login-list {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-top: 20px;

  > div {
    width: 33vw;
    text-align: right;
  }
}

.login-code-main {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-top: 20px;

  .login-code {
    width: 140px;
    height: 40px;
  }

  .login-code-input {
    width: 30vw;
  }

  .code-fresh-btn {
    padding: 0 10px;
    height: 30px;
    line-height: 30px;
    background: #ff6347;
    color: white;
    font-weight: bold;
    margin-left: 10px;
    font-size: 12px;
  }
}

.login-btn {
  margin: auto;
  margin-top: 15vh;
  background: red;
  color: white;
  width: 30vw;
  font-weight: bold;
  padding: 8px 0;
  font-size: 15px;
}
</style>
